import Vue from 'vue'
import Vuex from 'vuex';

Vue.use(Vuex);
// 再这里测试全局变量情况 
const store = new Vuex.Store({
  state: {
    count: 0,
    name:"haha"
  },
  //查询
  getters:{
  	getname:state => state.name,
  },
  mutations: {
    increments (state) {
      state.count++
    },
    setTotal(state){
    	state.count++
    },
    setasy(state){
    	setTimeout(() => {
	      state.count++
	    }, 5000)

    }
  },
  actions: {
    increment (context) {
	   setTimeout(() => {
	      context.commit('increments')
	    }, 5000)
    	console.log(44,context)
      
    },
    sets({commit},data){
    	console.log(55,data)
    	commit('setasy')
    },
    async funcs({commit}){
    	const res = await store.commit('setasy') // 等待 actionA 完成
    	console.log(999)
    }
  }
})

console.log(7,store.state)
// store.dispatch('increment')
//console.log(8,store.state)
store.dispatch('sets',1)
// console.log(9,store.state)

store.dispatch('funcs')

export default store
